import { createRouter, createWebHistory } from 'vue-router';
import Dashboard from '@/views/ht/ch/Dashboard.vue'; // 后台首页
import OrderManagement from '@/views/ht/ch/OrderManagement.vue'; // 订单管理
import ShopManagement from '@/views/ht/ch/ShopManagement.vue'; // 店铺管理
import GoodsList from '@/views/ht/ch/GoodsList.vue'; // 商品列表
import GoodsAdd from '@/views/ht/ch/GoodsAdd.vue'; // 商品添加
import GoodsCategory from '@/views/ht/ch/GoodsCategory.vue'; // 商品分类
import AccountList from '@/views/ht/ch/AccountList.vue'; // 账号列表
import AccountAdd from '@/views/ht/ch/AccountAdd.vue'; // 账号添加
import AccountRole from '@/views/ht/ch/AccountRole.vue'; // 账号角色
import SalesStatistics from '@/views/ht/ch/SalesStatistics.vue'; // 销售统计
import OrderStatistics from '@/views/ht/ch/OrderStatistics.vue'; // 订单统计  
import Login from '@/views/login/login.vue';
import Ht from '@/views/ht/Ht.vue';

const routes = [
  // 默认路由
  {
    path: '/',
    redirect: '/login',
  },

  // 登录页面
  {
    path: '/login',
    name: 'Login',
    component: Login,
  },
  {
    path: '/ht',
    name: 'Ht',
    component: Ht,
    redirect: '/ht/dashboard', // 重定向到后台首页
    meta: {
      breadcrumbTitle: '外卖商家中心',
      breadcrumbTo: { name: 'Ht' }
    },
    children: [
      // 后台首页
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: Dashboard,
        meta: {
          breadcrumbTitle: '后台首页',
          breadcrumbTo: { name: 'Dashboard' }
        }
      },

      // 订单管理
      {
        path: 'order-management',
        name: 'OrderManagement',
        component: OrderManagement,
        meta: {
          breadcrumbTitle: '订单管理',
          breadcrumbTo: { name: 'OrderManagement' }
        }
      },

      // 店铺管理
      {
        path: 'shop-management',
        name: 'shopManagement',
        component: ShopManagement,
        meta: {
          breadcrumbTitle: '店铺管理',
          breadcrumbTo: { name: 'shopManagement' }
        }
      },

      // 商品管理
      {
        path: 'goods',
        redirect: 'goods/list', // 重定向到商品列表
        meta: {
          breadcrumbTitle: '商品管理',
          breadcrumbTo: { name: 'GoodsList' }
        },
        children: [
          {
            path: 'list',
            name: 'GoodsList',
            component: GoodsList,
            meta: {
              breadcrumbTitle: '商品列表',
              breadcrumbTo: { name: 'GoodsList' }
            }
          },
          {
            path: 'add',
            name: 'GoodsAdd',
            component: GoodsAdd,
            meta: {
              breadcrumbTitle: '商品添加',
              breadcrumbTo: { name: 'GoodsAdd' }
            }
          },
          {
            path: 'category',
            name: 'GoodsCategory',
            component: GoodsCategory,
            meta: {
              breadcrumbTitle: '商品分类',
              breadcrumbTo: { name: 'GoodsCategory' }
            }
          }
        ]
      },

      // 账号管理
      {
        path: 'account',
        redirect: 'account/list', // 重定向到账号列表
        meta: {
          breadcrumbTitle: '账号管理',
          breadcrumbTo: { name: 'AccountList' }
        },
        children: [
          {
            path: 'list',
            name: 'AccountList',
            component: AccountList,
            meta: {
              breadcrumbTitle: '账号列表',
              breadcrumbTo: { name: 'AccountList' }
            }
          },
          {
            path: 'add',
            name: 'AccountAdd',
            component: AccountAdd,
            meta: {
              breadcrumbTitle: '账号添加',
              breadcrumbTo: { name: 'AccountAdd' }
            }
          },
          {
            path: 'role',
            name: 'AccountRole',
            component: AccountRole,
            meta: {
              breadcrumbTitle: '账号角色',
              breadcrumbTo: { name: 'AccountRole' }
            }
          }
        ]
      },

      // 销售统计
      {
        path: 'sales',
        redirect: 'sales/statistics', // 重定向到销售统计
        meta: {
          breadcrumbTitle: '销售统计',
          breadcrumbTo: { name: 'SalesStatistics' }
        },
        children: [
          {
            path: 'statistics',
            name: 'SalesStatistics',
            component: SalesStatistics,
            meta: {
              breadcrumbTitle: '商品统计',
              breadcrumbTo: { name: 'SalesStatistics' }
            }
          },
          {
            path: 'order-statistics',
            name: 'OrderStatistics',
            component: OrderStatistics,
            meta: {
              breadcrumbTitle: '订单统计',
              breadcrumbTo: { name: 'OrderStatistics' }
            }
          }
        ]
      }
    ]
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

// 添加全局路由守卫，方便查看路由跳转信息辅助排查问题
router.beforeEach((to, from, next) => {
  console.log('即将从', from.fullPath, '跳转到', to.fullPath);
  next();
});

export default router;
